<?php

class LoanWriteOffs extends HTech_Db_Table
{
    protected $_name     = 'view_loan_write_offs';
    protected $_primary  = 'LoanId';
    
    protected $_dependentTables = array('LoanWriteOffCharges','LoanWriteOffPayments','Payments'); 
    
    protected function _setGridMetadata()
    {
        $this->_gridMetadata['title'] = $this->translate("Legal");
        $this->_gridMetadata['titleMods'] = array('Status','LocationShortName','OfficerUsername','Program','ProductLine');
        $this->_gridMetadata['params'] = array('LoanId','LocationId','OfficerUserId','Status','LocationShortName','OfficerUsername','ProgramId','ProductLineId');
        $this->_gridMetadata['onClick'] = 'loan.legal.view';
        $this->_gridMetadata['headers'] = array
            (
                array('WriteOffId',          50, $this->translate("Id"),              'Number'),
                array('LoanId',              70, $this->translate("Loan"),            'Number'),
                array('ClientId',            70, $this->translate("Client id"),       'Number'),
                array('ClientCode',         100, $this->translate("Client gov. id"),  'String'),
                array('ClientFullName',     140, $this->translate("Client"),          'String'),
                array('ClientPhone',        100, $this->translate("Phone"),           'String'),
                array('LocationShortName',   80, $this->translate("Branch"),          'String'),
                array('OfficerUsername',     80, $this->translate("Officer"),         'String'),
                array('Community',          140, $this->translate("Community"),       'String'),
                array('ProductLineCode',     80, $this->translate("Line"),            'String'),
                array('FundCode',            80, $this->translate("Fund"),            'String'),
                array('Program',            120, $this->translate("Program"),         'String'),
                array('LoanProductName',    120, $this->translate("Product"),         'String'),
                array('PrincipalDisbursed', 100, $this->translate("Principal disb."), 'Number',   'Standard'),
                array('Principal',          100, $this->translate("WO principal"),    'Number',   'Standard'),
                array('DeliveryDate',        80, $this->translate("Disb. date"),      'DateTime', 'Date'),
                array('WriteOffDate',        80, $this->translate("WO date"),         'DateTime', 'Date')
            );
        return $this;
    }
    
    protected function _setRecordDependentRows()
    {
        $this->_record->r = (object) array('charges' => null, 'payments' => null, 'regularPayments' => null);
        $this->_record->r->charges = $this->_record->d->findDependentRowset('LoanWriteOffCharges'); 
        $this->_record->r->payments = $this->_record->d->findDependentRowset('LoanWriteOffPayments'); 
        $this->_record->r->regularPayments = $this->_record->d->findDependentRowset('Payments');     
    }
}